#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
const int N = 30;

int cnt[N];

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        memset(cnt, 0, sizeof cnt);
        string s1, s2;
        cin >> s1 >> s2; 
        cnt[s1[0] - 'a'] ++, cnt[s1[1] - 'a'] ++;
        cnt[s2[0] - 'a'] ++, cnt[s2[1] - 'a'] ++;
        int maxnum = -1, maxcolor = -1;
        for(int i = 0; i < 26; i ++){
            if(cnt[i] > maxnum){
                maxnum = cnt[i];
                maxcolor = i;
            }
        }

        int res = 0;
        for(int i = 0; i < 26; i ++){
            if(i != maxcolor && cnt[i]){
                res ++;
            }
        }

        cout << res << '\n';
    }



    return 0;
}